import mysql.connector as mc

# alt + ctrl +l

# config = {
#     'user': 'Hanamaki',
#     'host': '192.168.0.152',
#     'port': '3306',
#     'password': 'root',
#     'database': 'examtest',
#     'charset': 'utf8'
# }
con = None
try:
    con = mc.connect(
        user='root',
        host='127.0.0.1',
        port=3306,
        password='123456',
        database='examtest',
        charset='utf8'
    )
except mc.Error as e:
    print('数据库连接失败', str(e))
else:
    print("连接成功！")
finally:
    con.close()

if __name__ == '__main__':
    pass
